<template>
  <div id="safe_audit">
    <p>页面数据的百分比:<el-progress :text-inside="true"  :stroke-width="24" :percentage="max" status="success"></el-progress></p>
    <!-- 查询条件 -->
    <el-form :inline="true" :model="info" class="demo-form-inline">
      <el-form-item label="请选择仓库id:">
        <el-input v-model="info.search_stockId" placeholder="仓库id"></el-input>
      </el-form-item>
      <el-form-item label="请选择商品名称:">
        <el-input v-model="info.search_stockName" placeholder="商品名称"></el-input>
      </el-form-item>
      <el-form-item label="请输入审核时间" required>
        <el-col :span="11">
          <el-form-item prop="date1">

            <el-date-picker type="datetime" v-model="info.search_checkTime1" placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-form-item prop="date2">
            <el-date-picker type="datetime" v-model="info.search_checkTime2" placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="search" round>查询按钮</el-button>
        <el-button type="success" @click="showById3()" round>添加</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="arrList1" style="width: 100%">
      <el-table-column prop="stockId" label="仓库id" width="150">
      </el-table-column>
      <el-table-column prop="stockName" label="仓库名称" width="150">
      </el-table-column>
      <el-table-column prop="remark" label="描述" width="150">
      </el-table-column>
      <el-table-column prop="maxAmount" label="库存报警上限" width="150">
      </el-table-column>
      <el-table-column prop="minAmount" label="库存报警下限" width="150">
      </el-table-column>
      <el-table-column prop="maxCapacityAmount" label="最大存储量" width="150">
      </el-table-column>
      <el-table-column prop="amount" label="当前存储量" width="150">
      </el-table-column>
<!--      <el-table-column prop="onOff" label="是否启用" width="150">-->
<!--        <template slot-scope="scope">-->
<!--          {{ scope.row.onOff == "1" ? "启用" : (scope.row.onOff == "2" ? "禁用" : "禁用") }}-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column prop="register" label="登记人" width="150">
      </el-table-column>
<!--      <el-table-column prop="registerTime" label="登记时间" width="150">-->
<!--      </el-table-column>-->
<!--      <el-table-column prop="checkTime" label="审核时间" width="150">-->
<!--      </el-table-column>-->
<!--      <el-table-column prop="checkReason" label="审核理由" width="150">-->
<!--      </el-table-column>-->
<!--      <el-table-column prop="checkTag" label="审核状态" width="150">-->
<!--        <template slot-scope="scope">-->
<!--          {{ scope.row.checkTag == "S001-3" ? "审核通过" : (scope.row.checkTag == "S001-2" ? "审核未通过" : "等待审核") }}-->
<!--        </template>-->
<!--      </el-table-column>-->
      <!--操作列-->
      <el-table-column label="修改">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="showById(scope.$index, scope.row)" round>修改</el-button>
        </template>
      </el-table-column>
      <el-table-column label="审核" style="width: 50%">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="showById2(scope.$index, scope.row)" round>审核</el-button>
        </template>
      </el-table-column>
      <el-table-column label="删除" style="width: 50%">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="open(scope.$index, scope.row)" round>删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加仓库弹出对话框 -->
    <el-dialog title="添加仓库" :visible.sync="dialogVisibleAdd" width="60%">
        <el-form :inline="true" :model="filebean" class="demo-form-inline">
          <el-form-item label="仓库名称">
            <el-input v-model="filebean.stockName" placeholder="仓库名称"></el-input>
          </el-form-item>
          <el-form-item label="库存报警上限">
            <el-input v-model="filebean.maxAmount" placeholder="库存报警上限"></el-input>
          </el-form-item>
          <el-form-item label="库存报警下限">
            <el-input v-model="filebean.minAmount" placeholder="库存报警下限"></el-input>
          </el-form-item>
          <el-form-item label="最大存储量">
            <el-input v-model="filebean.maxCapacityAmount" placeholder="最大存储量"></el-input>
          </el-form-item>
          <el-form-item label="是否启用">
            <el-input v-model="filebean.onOff" placeholder="是否启用"></el-input>
          </el-form-item>
        </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleAdd = false">取 消</el-button>
          <el-button type="primary" @click="addStock">确 定</el-button>
      </span>
    </el-dialog>
    <!--    仓库审核弹出对话框-->
    <el-dialog
        title=""
        :visible="dialogVisibleCheck"
        @close="dialogVisibleCheck = false"
    >
      <!-- 对话框内容 -->
      <h3 style="text-align: center;">仓库审核</h3>
      <el-form :model="addForm">
          <!-- 添加 id 字段 -->
          <el-form-item label="仓库id" :label-width="formLabelWidth">
            <el-input v-model="addForm.stockId" placeholder="仓库id"></el-input>
          </el-form-item>
          <el-form-item label="仓库名称">
            <el-input v-model="addForm.stockName" placeholder="仓库名称"></el-input>
          </el-form-item>
          <el-form-item label="库存报警上限">
            <el-input v-model="addForm.maxAmount" placeholder="库存报警上限"></el-input>
          </el-form-item>
          <el-form-item label="库存报警下限">
            <el-input v-model="addForm.minAmount" placeholder="库存报警下限"></el-input>
          </el-form-item>
          <el-form-item label="最大存储量">
            <el-input v-model="addForm.maxCapacityAmount" placeholder="最大存储量"></el-input>
          </el-form-item>
          <el-form-item label="是否启用">
            <el-input v-model="addForm.onOff" placeholder="是否启用"></el-input>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleCheck = false">取 消</el-button>
        <el-button type="primary" @click="checkClass">复核通过</el-button>
      </div>
    </el-dialog>
    <!-- 修改弹出对话框 -->
    <el-dialog title="动态库存修改" :visible.sync="dialogVisibleUpdate" width="60%">
      <el-form :inline="true" :model="showGather" class="demo-form-inline">
        <!-- 添加 id 字段 -->
        <el-form-item label="仓库id" :label-width="formLabelWidth">
          <el-input v-model="showGather.stockId" placeholder="仓库id"></el-input>
        </el-form-item>
        <el-form-item label="仓库名称">
          <el-input v-model="showGather.stockName" placeholder="仓库名称"></el-input>
        </el-form-item>
        <el-form-item label="库存报警上限">
          <el-input v-model="showGather.maxAmount" placeholder="库存报警上限"></el-input>
        </el-form-item>
        <el-form-item label="库存报警下限">
          <el-input v-model="showGather.minAmount" placeholder="库存报警下限"></el-input>
        </el-form-item>
        <el-form-item label="最大存储量">
          <el-input v-model="showGather.maxCapacityAmount" placeholder="最大存储量"></el-input>
        </el-form-item>
        <el-form-item label="是否启用">
          <el-input v-model="showGather.onOff" placeholder="是否启用"></el-input>
        </el-form-item>
        <el-form-item label="审核状态">
          <el-input v-model="showGather.checkTag" placeholder="审核状态"></el-input>
          <template slot-scope="scope">
            {{ scope.row.checkTag === "S001-3" ? "审核通过" : (scope.row.checkTag === "S001-2" ? "审核未通过" : "等待审核") }}
          </template>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleUpdate = false">取 消</el-button>
          <el-button type="primary" @click="updateGather">确 定</el-button>
      </span>
    </el-dialog>
    <!---分页组件-->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
                   :page-sizes="pageSizeList" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                   :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arrList1: [],
      info: {
        search_stockId: '',
        search_stockName: '',
        search_checkTime1: '',
        search_checkTime2: '',
      },
      // 当前页号
      currentPage: 1,
      // 当前页大小
      pageSize: 2,
      // 总记录数
      total: 0,
      // 页大小列表
      pageSizeList: [2, 5, 10, 20],
      dialogVisible: false,
      dialogVisibleAdd: false,
      dialogVisibleUpdate: false,
      dialogVisibleCheck: false,
      //定义到对话框的值
      filebean: {

      },
      // 审核表单的对象
      addForm: {

      },
      showGather: {

      },
      max:0,
      registerTime:"",
      checkTime:"",
    }
  },
  methods: {
    async list() {
      const { data: res } = await this.$http.post
      (`/community/stock/show/${this.currentPage}/${this.pageSize}`)
      this.arrList1 = res.rows
      this.total = res.total
      let aaa=this.total/1
      if(aaa=="Infinity"){
        this.max=0
      }else{
        this.max=aaa
      }
    },
    //修改回显
    async showById(index, row) {
      console.log('row',row)
      const { data: res } = await this.$http.post
      (`/community/stock/showById?stockId=${row.stockId}`)
      this.showGather = res
      this.dialogVisibleUpdate = true
    },
    //修改请求
    async updateGather(index, row) {
      console.log('row',row)
      const { data: res } = await this.$http.post
      (`/community/stock/updateById`,this.filebean)
      this.filebean = res
      this.dialogVisible = true
    },
    //复核回显
    async showById2(index, row) {
      console.log('row',row)
      const { data: res } = await this.$http.post
      (`/community/stock/showById?stockId=${row.stockId}`)
      this.addForm = res
      this.dialogVisibleCheck = true
    },
    //添加仓库
    async showById3() {
      this.dialogVisibleAdd = true
    },
    async addStock() {
      const res = await this.$http.post
      (`/community/stock/add`,this.filebean)
      this.filebean = res
      alert('添加成功')
    },
    async open(index, row) {
      try {
        await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        });
        const { data: res } = await this.$http.post(`/community/stock/del?stockId=${row.stockId}`);
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      } catch (error) {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      }
    },
    //发送复核请求
    async checkClass() {
      try {
        const res = await this.$http.post(`/community/stock/update3/${this.currentPage}/${this.pageSize}`, this.addForm);
        console.log('addForm', this.addForm);
        console.log('res', res);
        if (res && res.data === true) {
          // 成功逻辑
          this.dialogVisibleCheck = false;
          // 消息提示
          this.$message('复核成功');
          // 刷新表格
          this.list();
        } else {
          // 失败逻辑
        }
      } catch (error) {
        console.error('Error in checkClass:', error);
        // 错误逻辑
      }
    },
    // 页大小改变
    handleSizeChange(val) {
      this.pageSize = val
      this.list()
    },
    // 页号改变
    handleCurrentChange(val) {
      this.currentPage = val
      // 重新查询
      this.list()
    },
  },
  // 表单查询
  search() {
    // 查询
    this.currentPage = 1
    this.list()
  },
  created() {
    this.list()
  }
}
</script>

<style>

</style>